package com.yyi.springcloud.service.impl;


import com.yyi.springcloud.dao.CoordonateInfoMapper;
import com.yyi.springcloud.entities.CoordonateInfoModel;
import com.yyi.springcloud.entities.CoordonateVo;
import com.yyi.springcloud.service.Local_CoordonateInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

@Service
public class Local_CoordinateInfoServiceImpl implements Local_CoordonateInfoService {

    @Resource
    private CoordonateInfoMapper coordonateInfoMapper;

    @Override
    public List<CoordonateInfoModel> getCoordonateInfoByCondition(CoordonateInfoModel coordonateInfoModel) {
        Example example = new Example(CoordonateInfoModel.class);
        //example.selectProperties("coordinateno","name");
        //example.setDistinct(true);
        //example.setOrderByClause("coordinateno");
        Example.Criteria criteria = example.createCriteria();
        if(coordonateInfoModel!=null){
            return null;
        }
        if(StringUtils.isEmpty(coordonateInfoModel.getLabcode())){
            criteria.andEqualTo("labcode",coordonateInfoModel.getLabcode());
        }
        if(StringUtils.isEmpty(coordonateInfoModel.getPrimarykey())){
            criteria.andLike("primarykey",coordonateInfoModel.getPrimarykey()+"%");
        }
        return coordonateInfoMapper.selectByExample(example);
    }

    @Override
    public List<CoordonateVo> selectCoordonate(CoordonateInfoModel coordonateInfoModel) {
        return coordonateInfoMapper.selectCoordonate(coordonateInfoModel);
    }

    @Override
    public int updateCoordonateInfo(String primaryKey, String coordinateno,Integer highvalue,Integer lowvalue) {
        Example example = new Example(CoordonateInfoModel.class);
        Example.Criteria criteria = example.createCriteria();
        if(primaryKey.isEmpty()||coordinateno.isEmpty()){
            return 0;
        }
        criteria.andLike("primarykey",primaryKey+"%");
        criteria.andEqualTo("coordinateno",coordinateno);
        CoordonateInfoModel coordonateInfoModel=new CoordonateInfoModel();
        coordonateInfoModel.setPrimarykey(primaryKey);
        coordonateInfoModel.setCoordinateno(Integer.parseInt(coordinateno));
        coordonateInfoModel.setHighvalue(highvalue);
        coordonateInfoModel.setLowvalue(lowvalue);
        int result = coordonateInfoMapper.updateByExampleSelective(coordonateInfoModel, example);
        return result;
    }
}

